package com.jjlin.leetcode.biweekly_contest.no40_2020_11_28;

import com.jjlin.leetcode.ListNode;

//合并两个链表
public class Solution2 {

    //直接模拟
    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
        ListNode p = list1, q = list1;
        for(int i = 0; i < a - 1; i++)
            p = p.next;
        for(int i = 0; i < b + 1; i++)
            q = q.next;
        p.next = list2;
        while(list2.next != null)
            list2 = list2.next;
        list2.next = q;
        return list1;
    }
}
